/*
 * This file is part of Plop Messenger.
 *
 * Plop Messenger is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  Plop Messenger is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Plop Messenger.  If not, see <http://www.gnu.org/licenses/>.
 */
package pm.ui;

import java.util.ArrayList;
import java.util.List;

import pm.Chan;
import pm.ChanFactory;

public class MainFrameChanFactory implements ChanFactory {

	private List<ChanelPanel> chans = new ArrayList<ChanelPanel>();

	private MainFrame mainFrame;

	public MainFrameChanFactory(MainFrame mainFrame) {
		this.mainFrame = mainFrame;
	}

	public Chan createChan(String name) {
		ChanelPanel panel = new ChanelPanel();
		chans.add(panel);
		mainFrame.addChanelPanel(name, panel);
		return panel;
	}

	@Override
	public void removeChan(Chan chan) {
		if (chans.contains(chan)) {
			chans.remove(chan);
			mainFrame.removeChanelPanel((ChanelPanel) chan);
		}
	}

}
